# 3.1 LED Blink ## 3.1.1 Overview LED Blink is one of the simplest entry-level programming projects for the ESP32 Coding Box. It only needs an LED and then upload the code. This simple project helps beginners better master basic concepts. ## 3.1.2 Schematic Diagram ![t40](./media/t40.png) **LED lighting on:** The output current of the IO ports is limited, so the LED brightness may not be enough. Therefore, a NPN triode (Q2) is added to the circuit as a switch. We only need to add a high(low) level at the triode base pin 1 to light it up(out). **Triode on/off:** To put it simple, when the base(pin 1) receives a high level, the collector(pin 3) and the transmitter(pin 2) are connected, so then VCC passes through the current-limiting resistor to the LED and then into the triode to GND, forming a loop. At this time, LED is on. When pin 1 receives a low level, pin 3 and 2 are disconnected so the current loop cannot be formed, resulting LED off. ## 3.1.3 Code Blocks Blocks in ![](./media/control.png): 1. ![t1](./media/t1.png) is in “Control” class. Click the green ![image-20250411084853429](./media/image-20250411084853429.png) to run the code. These hat blocks monitor the various conditions described in their titles. When the startup condition is true, **when started** will be activated. The others are to check whether the button status or Boolean conditions are true to determine whether to execute the blocks placed under them. 2. ![t2](./media/t2.png), a C-shaped block, also called LOOP, is a set of control blocks. As long as the conditions described in it are true, the inside codes will run. This repetitive execution will run the code blocks inside it forever. It is often used for plotting numerical values or continuously monitoring port values, etc. 3. ![t4](./media/t4.png) pauses the execution flow for the specified number of milliseconds. It is used to pause and resume the execution in a time-controlled manner. Unit conversion: 1 second = 1000 milliseconds -------------------------------- Blocks in ![](./media/codingBox.png): 1. ![t3](./media/t3.png) is a block included in coding box library. It can control the red, yellow and green LED on/off on the coding box. Click ![](./media/t5.png) to choose an LED and tap ![t6](./media/t6.png) to turn off it. ![t6](./media/t6.png) means ON, and ![t7](./media/t7.png) is OFF. ## 3.1.4 Test Code You can manually build blocks, or directly open the code file we provide: `3-1-LED.ubp`. If you have any questions about how to open code files or upload code, please back to `1.9 Upload Code`. **Build code blocks:** 1. In ![](./media/control.png), drag ![](./media/t1.png) and ![](./media/t2.png) to the script area, and stack them together. ![t34](./media/t34.png) 2. In ![](./media/codingBox.png), drag ![t3](./media/t3.png) block and place it in ![](./media/t2.png). ![t35](./media/t35.png) 3. In ![](./media/control.png), drag ![t4](./media/t4.png) block and modify `500` into `1000`, and put it under ![t3](./media/t3.png). ![t36](./media/t36.png) 4. Move your mouse onto ![t3](./media/t3.png) and click to choose `duplicate all`. Put the copy under the above blocks and set ![t3](./media/t3.png) to ![t37](./media/t37.png). ![t38](./media/t38.png) **Complete code:** ![t39](./media/t39.png) ## 3.1.5 Test Result Connect the coding box to the MicroBlocks via USB or Bluetooth, and click ![t59](./media/t59.png) to upload the code to the coding box. The red LED will blink with an interval of 1 second. If you want it to flash faster, modify the delay.